package com.sskj.givecoin.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.givecoin.MyAppLication;
import com.sskj.givecoin.m.HttpConfig;
import com.sskj.givecoin.m.bean.GoogleCode;
import com.sskj.givecoin.m.bean.HttpData;
import com.sskj.givecoin.m.http.JsonCallBack;
import com.sskj.givecoin.p.base.BasePresenter;
import com.sskj.givecoin.utils.ToastUtil;
import com.sskj.givecoin.v.activity.VerifyGoogleActivity;

/**
 * ProjectName：ioaex
 * DESC: (类描述)
 * Created by 李岩 on 2018/8/30 0030
 * updateName:(修改人名称)
 * updateTime:(修改时间)
 * updateDesc:(修改内容)
 */
public class VerifyGooglePresenter extends BasePresenter<VerifyGoogleActivity> {

    public void submit(String authCode, String googleAuthCode) {
        OkGo.<HttpData<Object>>post(HttpConfig.BASE_URL + "/home/google/checkGoogleCommand")
                .params("account", MyAppLication.getMobile())
                .params("code", authCode)
                .params("dyGoodleCommand", googleAuthCode)
                .execute(new JsonCallBack<HttpData<Object>>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData<Object>> response) {
                        ToastUtil.getInstance(MyAppLication.getApplication()).showMessage(response.body().getMsg());
                        mView.onBindSuccess();
                    }
                });
    }

    public void requestAuthCode() {
        OkGo.<HttpData<String>>post(HttpConfig.BASE_URL + "/home/google/setGoogleMsg")
                .execute(new JsonCallBack<HttpData<String>>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData<String>> response) {
                        ToastUtil.getInstance(MyAppLication.getApplication()).showMessage(response.body().getMsg());
                        mView.onAuthCodeSuccess();
                    }
                });
    }

    public void requestData() {
        OkGo.<HttpData<GoogleCode>>get(HttpConfig.BASE_URL + "/home/google/createGoogleCommand")
                .execute(new JsonCallBack<HttpData<GoogleCode>>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData<GoogleCode>> response) {
                        mView.onGoogleCodeSuccess(response.body().getData());
                    }
                });
    }

    public void sendEmail() {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SEND_EMAIL)
                .params("email", MyAppLication.getMobile())
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        ToastUtil.getInstance(MyAppLication.getApplication()).showMessage(response.body().getMsg());
                        mView.onAuthCodeSuccess();
                    }
                });
    }
}
